<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>学员管理列表</title>
    <link href="../../layui/css/layui.css" rel="stylesheet">
    <link href="css/layuiAdmin.css" rel="stylesheet">
    <link href="../../static/css/style.css" rel="stylesheet">
    <script src="../../static/js/jquery.min.js"></script>
    <script src="../../layui/layui.js"></script>
    <script src="../../static/js/base.js"></script>
    <script src="../../static/js/ax.js"></script>
    <script src="../../static/js/jquery.cookie.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="../../static/js/html5.js"></script>
    <script src="../../static/js/respond.js"></script>
    <![endif]-->

</head>

<body>

    <!--主体内容-->
    <div class="layui-fluid">
        <div class="layui-card content-wrap">
            <!--查询-->
            <div class="layui-form  layui-form-pane">
                <div class="layui-form-item layui-row layui-col-space15">
                    <div class="layui-col-md3 layui-col-sm6">
                        <label class="layui-form-label">学员列表</label>
                        <div class="layui-input-block">
                            <input type="text" id="NameOrNum" placeholder="请输入学员姓名或证件号码" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md3 layui-col-sm6">
                        <label class="layui-form-label">报名机构</label>
                        <div class="layui-input-block">
                            <input type="text" id="driverName" placeholder="请输入报名机构" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md3 layui-col-sm6">
                        <label class="layui-form-label">手机号码</label>
                        <div class="layui-input-block">
                            <input type="text" id="phone" placeholder="请输入手机号码" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md3 layui-col-sm6">
                        <label class="layui-form-label">准驾车型</label>
                        <div class="layui-input-block">
                            <select name="carId" id="carId">
                                <option value="0">全部</option>

                            </select>
                        </div>
                    </div>

                    <div class="layui-col-md3 layui-col-sm6">
                        <label class="layui-form-label">互联网状态</label>
                        <div class="layui-input-block">
                            <select name="netStatus" id="netStatus">
                                <option value="">全部</option>
                                <option value="onsubmit">未提交</option>
                                <option value="waitsubmit">待提交</option>
                                <option value="saved">已保存</option>
                                <option value="uploadok">上传成功</option>
                                <option value="uploadon">上传失败</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-col-md3 layui-col-sm6">
                        <label class="layui-form-label">业务状态</label>
                        <div class="layui-input-block">
                            <select name="innerStatus" id="innerStatus">
                                <option value="">全部</option>
                                <option value="normal">正常</option>
                                <option value="conclude">办结</option>
                                <option value="retreats">退办</option>
                                <option value="aboutExamOk">约考审核成功</option>
                                <option value="aboutExamFail">约考审核失败</option>
                                <option value="checkOk">复核成功</option>
                                <option value="checkFail">复核失败</option>
                                <option value="certificationOk">制证成功</option>
                                <option value="certificationFail">制证失败</option>
                                <option value="fileOk">归档成功</option>
                                <option value="fileFail">归档失败</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-col-md3 layui-col-sm6">
                        <label class="layui-form-label">时间类型</label>
                        <div class="layui-input-block">
                            <select name="timeType" id="timeType">
                                <option value="">全部</option>
                                <option value="0">创建时间</option>
                                <option value="1">提交时间</option>
                                <option value="2">报名日期</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-col-md3 layui-col-sm6">
                        <label class="layui-form-label">开始时间起</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input" id="timeStart" placeholder="yyyy-MM-dd">
                        </div>
                    </div>

                    <div class="layui-col-md3 layui-col-sm6">
                        <label class="layui-form-label">结束时间至</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input" id="timeEdd" placeholder="yyyy-MM-dd">
                        </div>
                    </div>

                    <div class="layui-col-md3 layui-col-sm6">
                        <label class="layui-form-label">证件类型</label>
                        <div class="layui-input-block">
                            <select name="sfType" id="sfType">

                            </select>
                        </div>
                    </div>


                    <div class="layui-col-md3 layui-col-sm6">
                        <label class="layui-form-label">学员状态</label>
                        <div class="layui-input-block">
                            <select name="status" id="status">
                                <option value="">全部</option>
                                <option value="newenroll">新报名</option>
                                <option value="joink1">科目一在培中</option>
                                <option value="kone">科目一预约考试中</option>
                                <option value="joink2">科目二在培中</option>
                                <option value="k2">科目二预约考试中</option>
                                <option value="joink3">科目三在培中</option>
                                <option value="k3">科目三预约考试中</option>
                                <option value="joink4">科目四在培中</option>
                                <option value="k4">科目四约考试中</option>
                                <option value="edd">已结业</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-inline layui-col-md3 layui-col-sm6 selectButton">
                        <button id="show" class="layui-btn add_btn" data-type="reload">
                            <i class="layui-icon layui-icon-search"></i>搜索</button>
                        <button class="layui-btn delete_btn" data-type="reloadClean">
                            <i class="layui-icon layui-icon-delete"></i>清空</button>
                    </div>
                </div>
            </div>


            <!--数据列表展示-->
            <div>
                <script type="text/html" id="toolbarDemo">
                <div>
                    <button class="layui-btn layuiadmin-btn-useradmin ax-btn add_btn" lay-event="addStudent" >学员录入</button>
                    <button class="layui-btn layuiadmin-btn-useradmin add_btn ax-btn" lay-event="selectStudent" >查看</button>
                    <button class="layui-btn layuiadmin-btn-useradmin add_btn ax-btn" lay-event="addDriver" >增驾</button>
                    <button class="layui-btn layuiadmin-btn-useradmin change_btn ax-btn" lay-event="updateStudet" ><i class="layui-icon layui-icon-edit"></i>编辑</button>
                    <button class="layui-btn layuiadmin-btn-useradmin add_btn ax-btn" lay-event="submit122">批量提交122</button>
                    <button class="layui-btn layuiadmin-btn-useradmin delete_btn ax-btn" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</button>
                    <button class="layui-btn layuiadmin-btn-useradmin add_btn ax-btn" lay-event="export">导出excel</button>
                </div>
            </script>

                <table class="layui-hide" id="activeListTbale" lay-filter="active"></table>
            </div>


        </div>
    </div>
    <!--主体内容-->

</body>

<script>

    var table;
    var baseData = null;
    layui.use(['table', 'form', 'laydate', 'layer', 'element'], function () {
        table = layui.table;
        var form = layui.form,
            laydate = layui.laydate,
            layer = layui.layer;

        //常规用法
        laydate.render({
            elem: '#timeStart'

        });

        laydate.render({
            elem: '#timeEdd'

        });

        var tableIns = ax.VTable({
            elem: '#activeListTbale',
            url: schoolWebUrl + '/api/student/getStudentAll',
            id: 'testReload',
            toolbar: '#toolbarDemo',
            title: '学员数据列表',
            cols: [[
                { type: 'checkbox' },
                { field: 'id', width: 80, title: '序号' },
                { field: 'studentNumber', title: '学员编号', minWidth: 150 },
                { field: 'driversName', width: 150, title: '报名机构' },
                { field: 'name', width: 150, title: '姓名' },
                { field: 'certificatesNumber', width: 150, title: '证件号码' },
                { field: 'sfTypeName', width: 150, title: '证件类型' },
                { field: 'registeredSource', width: 150, title: '来源' },
                { field: 'carName', width: 150, title: '准驾车型' },
                { field: 'driversName', width: 150, title: '驾校名称' },
                { field: 'netStatusName', width: 150, title: '互联网状态' },
                { field: 'innerStatusName', width: 180, title: '业务状态' },
                { field: 'isBindingWechatName', width: 180, title: '是否微信绑定' },
                { field: 'wechatOpenid', width: 180, title: '微信号' },
                { field: 'created', width: 180, title: '创建时间' }
            ]]
        });

        var $ = layui.$, student = {
            reload: function () {

                var nameOrNum = $('#NameOrNum').val();
                var driverName = $('#driverName').val();
                var phone = $('#phone').val();
                var carId = $('#carId').val();
                var netStatus = $('#netStatus').val();
                var innerStatus = $('#innerStatus').val();
                var timeType = $('#timeType').val();
                var timeStart = $('#timeStart').val();
                var timeEdd = $('#timeEdd').val();
                var sfType = $('#sfType').val();
                var status = $('#status').val();

                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    },
                    where: {
                        nameOrNum: nameOrNum,
                        driverName: driverName,
                        phone: phone,
                        carId: carId,
                        netStatus: netStatus,
                        innerStatus: innerStatus,
                        timeType: timeType,
                        timeStart: timeStart,
                        timeEdd: timeEdd,
                        sfType: sfType,
                        status: status
                    }
                });
            },
            reloadClean: function () {
                $('#NameOrNum').val("");
                $('#driverName').val('');
                $('#phone').val('');
                $('#carId').val('');
                $('#netStatus').val('');
                $('#innerStatus').val('');
                $('#timeType').val('');
                $('#timeStart').val('');
                $('#timeEdd').val('');
                $('#sfType').val('');
                $('#status').val('');
                form.render('select');//重新加载select
                table.reload('testReload');
            }
        };

        $('.selectButton .layui-btn').on('click', function () {
            var type = $(this).data('type');//获取reload
            student[type] ? student[type].call(this) : '';
        });

        //头工具栏事件
        table.on('toolbar()', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            switch (obj.event) {
                case 'del':
                    if (data.length <= 0) {
                        top.layer.open({
                            title: '信息提示'
                            , content: '请选择删除的数据！'
                        });
                        break;
                    }
                    layer.confirm('确定是否需要删除学员！', function (index) {
                        var ids = [];
                        for (var i = 0; i < data.length; i++) {
                            ids.push(data[i].id);
                        }
                        delStudent(ids);
                    })

                    break;
                case 'addStudent':
                    addStudent();
                    break;
                case 'updateStudet':
                    if (data.length != 1) {
                        top.layer.open({
                            title: '信息提示'
                            , content: '只能选择一个学员去修改！'
                        });
                        break;
                    }
                    updateStudet(data[0].id);
                    break;
                case 'selectStudent':
                    if (data.length != 1) {
                        top.layer.open({
                            title: '信息提示'
                            , content: '只能选择一个学员！'
                        });
                        break;
                    }
                    selectStudet(data[0].id);
                    break;
                case 'submit122':

                    getAll122();
                    break;
                case 'export':
                    if (data.length <= 0) {
                        top.layer.open({
                            title: '信息提示'
                            , content: '选择导出的数据不能为空！'
                        });
                        break;
                    }
                    var ids = [];
                    for (var i = 0; i < data.length; i++) {
                        ids.push(data[i].id);
                    }
                    var idss=ids.join(",");
                    console.log(idss);
                    window.location.href=schoolWebUrl +systemhl+ "/api/student/export?ids="+idss;
                    break;
            };
        });

        var initBaseData = function () {
            ax.get({
                url: schoolWebUrl + "/api/student/getBaseData",
                success: function (res) {
                    if (res.code == 0) {
                        baseData = res.data;
                        loadBaseData();
                    } else {
                        layer.msg(res.message);
                    }
                }

            });
        };

        var loadBaseData = function () {
            // 初始  证件
            $("#sfType").empty();
            $("#sfType").append("<option value=''>请选择</option>");
            $.each(baseData.zjTypeList, function (index, zj) {
                $("#sfType").append("<option value='" + zj.id + "'>" + zj.code + "</option>");
            });
            // 准驾车型列表
            $("#carId").empty();
            $("#carId").append("<option value=''>请选择</option>");
            $.each(baseData.carTypeList, function (index, carType) {
                $("#carId").append("<option value='" + carType.id + "'>" + carType.code + "</option>");
            });
            form.render('select');
            baseDataDone = true;
        };



        initBaseData();


    });


    //删除用户
    function delStudent(ids) {
        var data = { ids: ids };
        ax.get({
            url: schoolWebUrl + "/api/student/del",
            data: data,
            success: function (res) {
                layer.msg("删除成功");
                table.reload('testReload');
            },
            error: function (request) {
                layer.msg("系统错误，联系管理员");
                table.reload('testReload');
            }
        });
    }

    //添加
    function addStudent() {
        window.location.href = 'studentAdd.html';
    }

    //修改用户
    function updateStudet(studentId) {
        window.location.href = 'eidteStudent.html?id=' + studentId;
    }
    //批量提交122
    function getAll122() {
        // window.location.href = 'submit122.html';
        top.layer.open({
            type: 2,
            title:'批量提交122',
            area: ['90%', '80%'],
            fixed: true, //不固定
            maxmin: true,
            content: './school/student/submit122.html'
        });

    }


    //查看用户信息
    function selectStudet(studentId) {
        window.location.href = 'student_li.html?id=' + studentId;
    }


</script>

</html>